a = int(input())
if a // 10000 > 0:
    a = 0
elif a // 1000 == 0:
    a = 0
else:
    b = a % 10
    c = a // 10 % 10
    d = a // 100 % 10
    e = a // 1000 % 10
    f = a // 100
    g = a // 10 % 100
    h = a % 100
    i = a // 10
    j = a % 1000
    k = 2
    if b == 0 or 1:
        b = 0
    else:
        l = b / k
        while int(l) != l:
            k += 1
            l = b / k
        if k != b:
            b = 0
        elif b == k:
            b = b
    k = 2
    if c == 0 or 1:
        c = 0
    else:
        m = c / k
        while int(m) != m:
            k += 1
            m = c / k
        if k != c:
            c = 0
        elif c == k:
            c = c
    k = 2
    if d == 0 or 1:
        d = 0
    else:
        n = d / k
        while int(n) != n:
            k += 1
            n = d / k
        if k != d:
            d = 0
        elif d == k:
            d = d
    k = 2
    if e == 1:
        e = 0
    else:
        o = e / k
        while int(o) != o:
            k += 1
            o = e / k
        if k != e:
            e = 0
        elif e == k:
            e = e
    k = 2
    p = f / k
    while int(p) != p:
        k += 1
        p = f / k
    if k != f:
        f = 0
    elif f == k:
        f = f
    k = 2
    if g // 10 == 0:
        g = 0
    else:
        q = g / k
        while int(q) != q:
            k += 1
            q = g / k
        if k != g:
            g = 0
        elif g == k:
            g = g
    k = 2
    if h // 10 == 0:
        h = 0
    else:
        r = h / k
        while int(r) != r:
            k += 1
            r = h / k
        if k != h:
            h = 0
        elif h == k:
            h = h
    k = 2
    s = i / k
    while int(s) != s:
        k += 1
        s = i / k
    if k != i:
        i = 0
    elif k == i:
        i = i
    k = 2
    if j // 100 == 0:
        j = 0
    else:
        t = j / k
        while int(t) != t:
            k += 1
            t = j / k
        if k != j:
            j = 0
        elif k == j:
            j = j
    k = 2
    u = a / k
    while int(u) != u:
        k += 1
        u = a / k
    if a != k:
        a = 0
    elif a == k:
        a = a
    v = max(a, b, c, d, e, f, g, h, i, j)
    print(v)